# 提醒输入学生的学号，然后输入学生姓名，然后依次输入学生的语文、数学、英语成绩
# 需求如下：计算学员的总分和平均分
# 所有成绩浮点数，2位小数


def function(s_num, s_name, lan_score, math_score, eng_score):
    divid_row = "成绩统计"
    print(divid_row.center(40, '='))

    total_score = float(lan_score) + float(math_score) + float(eng_score)
    ave_score = total_score / 3

    print("学号：%s 姓名：%s " % (s_num, s_name))
    print("总分：%.2f 平均分：%.2f " % (total_score, ave_score))
    print("成绩明细：语文：%.2f 数学：%.2f 英语：%.2f " %
          (float(lan_score), float(math_score), float(eng_score)))
    print("=" * 44)


def check_input(result):
    try:
        if result == "":
            print("成绩不能为空")
        elif type(float(result)) is float and float(result) >= 0 and float(
                result) <= 100:
            return True
        else:
            return False
    except:
        return False


def print_out(s_num, s_name, subject):
    while True:
        result = input("请输入学号：%s 姓名：%s 的%s成绩：" % (s_num, s_name, subject))
        if check_input(result):
            return result
        else:
            print("输入正确的成绩0~100")
            continue


if __name__ == "__main__":
    s_num = input("输入学生学号：")
    s_name = input("输入学生姓名： ")
    lan_score = print_out(s_num, s_name, "语文")
    math_score = print_out(s_num, s_name, "数学")
    eng_score = print_out(s_num, s_name, "英语")
    function(s_num, s_name, lan_score, math_score, eng_score)
